package com.cyh.AcquireEarestKpiStartTime;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author CYH
 * @date 2017/11/19 0019
 */
public class MainEarliestKpiStartTime {


    public static void main(String[] args) {
        new MainEarliestKpiStartTime().run();
    }

    private void run() {
        KpiData kpiData = new KpiData();
        kpiData.givenNewDate(new Date());
        Date date = new Date();
        date.setTime(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
        kpiData.givenNewDate(date);

        System.out.println("savedEarliestStartTime: " + kpiData.savedEarliestStartTime);
        System.out.println("firstWroteStartTime: " + kpiData.firstWroteStartTime);
    }


    class KpiData {
        Date firstWroteStartTime;
        Date savedEarliestStartTime;
        private boolean firstTime = true;

        public void givenNewDate(Date input) {
            if (savedEarliestStartTime == null || input.before(savedEarliestStartTime)) {
                savedEarliestStartTime = input;
                System.out.println("--savedEarliestStartTime: " + savedEarliestStartTime);
            }
            if (firstTime) {
                firstTime = false;
                // 17年初和Lillian在做的时候，用了 savedEarliestStartTime.clone(); 感觉是没有必要的
                firstWroteStartTime = savedEarliestStartTime;
                System.out.println("--firstWroteStartTime: " + firstWroteStartTime);
            }
        }

    }


}
